// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: cred specific symbols
 * Author: Huawei OS Kernel Lab
 * Create: Thu Sep 20 16:34:03 2022
 */

#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/splice.h>
#include <asm/override.h>

const struct file_operations pipefifo_fops;
const struct file_operations fscontext_fops;

/* dummy pipe ops for lib/iov_iter.c */
const struct pipe_buf_operations default_pipe_buf_ops;
const struct pipe_buf_operations page_cache_pipe_buf_ops;
const struct pipe_buf_operations nosteal_pipe_buf_ops;

DEFINE_SPINLOCK(mmlist_lock);

int __override tty_do_resize(struct tty_struct *tty, struct winsize *ws)
{
	/* Lock the tty */
	mutex_lock(&tty->winsize_mutex);
	if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
		goto done;

	if (tty->hmpgrp != 0)
		liblinux_pal_process_signal(tty->hmpgrp, SIGWINCH);
	tty->winsize = *ws;
done:
	mutex_unlock(&tty->winsize_mutex);
	return 0;
}

extern int dev_mkdir(const char *name, umode_t mode);
int liblinux_devtmpfs_setup(void *p)
{
	int err;

	err = unshare_fs_struct();
	if (err)
		goto out;
	err = dev_mkdir("/dev", 0755);
	if (err)
		goto out;
	err = init_mount("devtmpfs", "/dev", "devtmpfs", MS_SILENT, NULL);
	if (err)
		goto out;
	init_chdir("/dev");
	init_chroot(".");
out:
	*(int *)p = err;
	return err;
}


void __init __override proc_root_init(void)
{
	proc_init_kmemcache();
	register_filesystem(&proc_fs_type);

	proc_sys_init();
#ifdef CONFIG_LIBLINUX_NET_STACK
	proc_net_init();
#endif
	proc_mkdir("driver", NULL);
	proc_tty_init();
	proc_mkdir("bus", NULL);
}
